package com.example.testtts;

import java.util.Locale;

import android.content.Context;
import android.speech.tts.TextToSpeech;
import android.util.Log;

public class Text2Speech implements TextToSpeech.OnInitListener {
	private TextToSpeech tts;


	public Text2Speech(Context context) {
		tts = new TextToSpeech(context, this);
	}

	
	@Override
	public void onInit(int status) {

		if (status == TextToSpeech.SUCCESS) {

			int result = tts.setLanguage(Locale.US);
			 tts.setPitch(1); // set pitch level
			 tts.setSpeechRate((float) 0.5); // set speech speed rate
			if (result == TextToSpeech.LANG_MISSING_DATA
					|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
				Log.e("TTS", "Language is not supported");
			} else {
//				speakOut();
			}

		} else {
			Log.e("TTS", "Initilization Failed");
		}

	}
	
	public void speakOut(String text) {
		tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
	}
	


}
